package com.ourteam.product.api;

import java.util.Date;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ourteam.frame.controller.AbstractCRUDServiceController;
import com.ourteam.product.ui.dao.ProductUIListOptionDAOQueryBean;
import com.ourteam.product.ui.domain.ProductUIListOptionBean;
import com.ourteam.product.ui.service.IProductUIService;
import com.ourteam.product.ui.service.ProductUIServiceFactory;

@Controller
@RequestMapping("/api/PRODUCT/UI/productUIListOption")
public class ProductUIListOptionAPI extends
		AbstractCRUDServiceController<ProductUIListOptionDAOQueryBean, ProductUIListOptionSearchModel, ProductUIListOptionBean> {

	private static final IProductUIService PRODUCT_UI_SERVICE = ProductUIServiceFactory.getProductUIService();

	@Override
	protected ProductUIListOptionDAOQueryBean newQueryBean() {
		return new ProductUIListOptionDAOQueryBean();
	}

	@Override
	protected int queryCount(ProductUIListOptionDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUIListOptionCount(queryBean);
	}

	@Override
	protected ProductUIListOptionBean[] queryData(ProductUIListOptionDAOQueryBean queryBean) throws Exception {
		return PRODUCT_UI_SERVICE.queryProductUIListOptions(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {
		PRODUCT_UI_SERVICE.deleteProductUIListOptions(ids);
	}

	@Override
	protected ProductUIListOptionBean getDataById(long id) throws Exception {
		return PRODUCT_UI_SERVICE.getProductUIListOptionById(id);
	}

	@Override
	protected void saveData(ProductUIListOptionBean dataBean) throws Exception {
		dataBean.setLastModifyTime(new Date());
		dataBean.setLastModifyUser(getLoginUserName());
		if (dataBean.getId() == 0) {
			PRODUCT_UI_SERVICE.addNewProductUIListOption(dataBean);
		} else {
			PRODUCT_UI_SERVICE.modifyProductUIListOption(dataBean);
		}
	}

}
